package com.czlw.module_activity.fragment

import android.annotation.SuppressLint
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.clzw.module_activity.R
import com.clzw.module_activity.BR
import com.clzw.module_activity.databinding.FragmentBulletinDetailBinding
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.base.event.LiveBusCenter
import com.czl.module_activity.view.ActivityDetailWebViewClient
import com.czlw.module_activity.viewmodel.BulletinDetailViewModel

@Route(path = AppConstants.Router.Activities.F_ACTIVITIES_BULLENTIN_DETAIL)
class BulletinDetailFragment:BaseFragment<FragmentBulletinDetailBinding, BulletinDetailViewModel>() {
    override fun initContentView(): Int {
        return R.layout.fragment_bulletin_detail
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun initData() {
        viewModel.bulletinId= arguments?.getInt(AppConstants.BundleKey.BULLENTIN_ID)!!.toInt()
        viewModel.tvTitle.set("公告详情")
        binding.wbRichtext.isHorizontalScrollBarEnabled=false
        binding.wbRichtext.isVerticalScrollBarEnabled=false
        binding.wbRichtext.settings.javaScriptEnabled=true
        binding.wbRichtext.webViewClient= ActivityDetailWebViewClient()
        reload()
    }
    override fun initViewObservable() {
        viewModel.onRefreshFinishEvent.observe(this,{
            binding.smartCommon.finishRefresh(it)
            if (!it){
                showErrorStatePage()
            }else{
                showSuccessStatePage()
            }
        })
    }
    override fun reload() {
        super.reload()
        binding.smartCommon.autoRefresh()
    }

    override fun onDetach() {
        super.onDetach()
        LiveBusCenter.postBulletinRefreshEvent("")
    }
}